using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fated {
    public class Tree<dataType> {
        private List<Tree<dataType>> children;
        public dataType Data { get; set; }

        public Tree() {
            children = new List<Tree<dataType>>();
            Data = default(dataType);
        }
        public Tree(dataType initial) : this(){
            Data = initial;
        }

        public void Add(Tree<dataType> child) {
            children.Add(child);
        }
        public void Add(dataType child) {
            children.Add(new Tree<dataType>(child));
        }

        public Tree<dataType> tracePath(int[] path) {
            Tree<dataType> output = this;
            foreach (int i in path) {
                output = output[i];
            }
            return output;
        }

        public Tree<dataType> this[int i] {
            get {
                return children[i];
            }
            set {
                children[i] = value;
            }
        }

        public int Count() {
            return children.Count();
        }
    }
}
